package com.cskaoyan.javase.oop2._1extends._9override._1basic;

/**
 * "父类引用指向子类对象"时,父类引用指向子类对象和子类引用指向子类对象,有什么区别?
 *   区别在于引用的数据类型
 *   而引用的数据类型决定了访问范围
 *   也就是说,一旦使用"父类引用指向子类对象"
 *   这个父类引用就要限制子类对象的访问范围,如果某个成员子类独有而父类没有,这个时候就访问不到了.
 *
 * (了解即可,很少见)除此之外,还有在访问成员变量时,也有区别:
 * 当父子类出现同名成员时
 * 如果引用不同,访问结果由引用的数据类型来决定
 *
 * @since 14:58
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo {
    public static void main(String[] args) {
        Student s = new Student("张三", 18, 100, 666);
        System.out.println(s.name);
        System.out.println(s.score);
        Person ps = new Student("张三", 18, 100, 666);
        // ps.score
        // ps.stuId

        System.out.println(ps.age);
        System.out.println(ps.name);
        System.out.println("----------------------");

        Person ps2 = new Student();
        System.out.println(ps2.name);

        System.out.println("----------------------");
        Person ps3 = new Student("长风");
        System.out.println(ps3.name);
        Student s2 = new Student("长风");
        System.out.println(s2.name);
    }
}

class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }
}

class Student extends Person {

    String name;

    double score;
    int stuId;

    public Student() {
    }

    public Student(String name) {
        this.name = name;
    }

    public Student(String name, int age) {
        super(name, age);
    }

    public Student(String name, int age, double score, int stuId) {
        super(name, age);
        this.score = score;
        this.stuId = stuId;
    }
}
